<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="admin-sidebar" class="admin-sidebar">
    <ul id="menu" class="am-list admin-sidebar-list">
        <%--<li><a href="javascript:void(0);" style="color:#f37b1d;font-weight:bold;"><span class="am-icon-home"></span> 系统管理</a></li>--%>
    </ul>

</div>
<script>
    $(function(){
        initMenu();
        //alert($(window).height());
        $("#admin-sidebar").height($(window).height()-60);
        //openPage("main.html");

    });
    function initMenu(){
        doAjax("${ctx}/admin/menu/menuJson.do",null, function(data){
            var menus = data.menu;
            for(var i = 0; i < menus.length; i++){
                if(menus[i].parent == null || menus[i].parent.length == 0){
                    $("#menu").append('<li class=""><a class="am-cf c-active" href="javascript:void(0);" p="true" subId="'+menus[i].id+'"><span class="am-icon-minus-square"></span> '+menus[i].name+'</a></li>');
                    $("#menu").append('<ul class="am-list am-collapse admin-sidebar-sub am-in" id="sub_'+menus[i].id+'"></ul>');
                }else{
                    $("#sub_"+menus[i].parent).append('<li id="menu_'+menus[i].id+'"><a href="javascript:void(0);" url="'+menus[i].url+'" onclick="onMenu(this)">'+menus[i].name+'</a></li>');
                }
            }
            $("a[p='true']").bind({click: function(){
                var a = $(this);
                var $collapse = $("#sub_"+a.attr("subId"));
                $collapse.collapse('toggle');
                if(a.find("span").hasClass("am-icon-minus-square")){
                    a.find("span").removeClass();
                    a.find("span").addClass("am-icon-plus-square");
                }else{
                    a.find("span").removeClass();
                    a.find("span").addClass("am-icon-minus-square");
                }
            }});
            //设置菜单选中状态
            setActiveMenu('${param.mid}');
        });
    }
    function onMenu(item){
        //openPage($(item).attr("url"));
        var url = $(item).attr("url");
        if(url.indexOf("?") == -1){
        	url += "?mid="+$(item).parent().attr("id");
        }else{
        	url += "&mid="+$(item).parent().attr("id");
        }
        //url += "&decorator=admin";
        window.location.href = "${ctx}/"+url;
    }
    function setActiveMenu(mid){
    	//alert(mid);
    	$("#"+mid).addClass("am-menu-active");
    }
    function openPage(url){
        doAjax("${ctx}/ui/test/"+url, null, function(data){
            $("#main-content").empty();
            $("#main-content").append(data);
        },"html");
    }
    </script>